package algorithm.practice;

import java.util.Arrays;

/**
 * @description: 类描述
 * @author: Fesine
 * @createTime:2017/8/3 8:51
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2017/8/3 8:51
 */
public class BubbleSortPractice {
    public static void bubbleSort(int[] a) {
        int n = a.length;
        int tmp ;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n -i- 1; j++) {
                if (a[j] > a[j+1]){
                    tmp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = tmp;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] a = {3, 2, 9, 4, 7, 6,1};
        bubbleSort(a);
        System.out.println(Arrays.toString(a));
    }
}
